package cn.tedu.charging.order.rabbitmq.exchange;

import cn.tedu.charging.order.rabbitmq.ChannelManager;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import org.junit.jupiter.api.Test;

public class FanoutExchange {
    private static final String EXCHANGE_NAME="fanout_ex";
    //路由交换机 计算路由的逻辑
    @Test
    public void bindQueues2Fanout() throws Exception {
        //1.拿到连接对象channel
        Channel channel = ChannelManager.createChannel();
        //2.声明队列组件 queue1 queue2 queue3
        //2.1由于测试总是使用相同的队列,我们把队列清空一下
        channel.queueDelete("queue1");
        channel.queueDelete("queue2");
        channel.queueDelete("queue3");
        channel.queueDeclare("queue1",false,false,false,null);
        channel.queueDeclare("queue2",false,false,false,null);
        channel.queueDeclare("queue3",false,false,false,null);
        //3.声明交换机 只需要提供交换机的名字和类型
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT);
        //4.组织一下绑定关系
        channel.queueBind("queue1",EXCHANGE_NAME,"北京");
        channel.queueBind("queue2",EXCHANGE_NAME,"上海");
        channel.queueBind("queue3",EXCHANGE_NAME,"天津");
    }
}
